<template>
  <div>
    <div class="order-item-panel">
      <el-row class="order-item-panel_info">
        <el-col>
          <span>运费：</span>
          <span style="color: #fc4541">¥{{ details && details.freightTotalAmount }}</span>
        </el-col>
      </el-row>

      <el-row class="order-item-panel_tabs">
        <el-col :span="4">商品信息</el-col>
        <el-col class="text-center" :span="3">单价/成本/数量</el-col>
        <el-col class="text-center" :span="2">供应商</el-col>
        <el-col class="text-center" :span="2">实付金额</el-col>
        <el-col class="text-center" :span="3">支付类型</el-col>
        <el-col class="text-center" :span="4">钱款去向</el-col>
        <el-col class="text-center" :span="3">订单状态</el-col>
        <el-col class="text-center" :span="3">操作</el-col>
      </el-row>

      <el-row class="panel-content" v-for="item in detailList" :key="item.goodsSkuId">
        <el-col :span="4">
          <div>
            <div class="flex">
              <el-image
                class="panel-content-img"
                :src="item.goodsSkuGraph"
                :preview-src-list="[item.goodsSkuGraph]"
              />
              <div class="panel-content-text flex flex-col justify-between ml-5">
                <p class="panel-content_title" style="color: #293c66">{{ item.goodsName }}</p>
                <p>{{ item.goodsSkuName }}</p>
              </div>
            </div>
            <p v-if="item.goodsSupply" class="mt-10" style="color: #409eff">
              {{ item.goodsSupply.name }}
            </p>
          </div>
        </el-col>
        <el-col :span="3" class="text-center">
          <p>{{ item.goodsPrice }}</p>
          <p class="mt-10">¥{{ item.costPrice }}</p>
          <p class="mt-10">{{ item.goodsNum }}</p>
        </el-col>
        <el-col :span="2" class="text-center"> {{ item.supplierName || '暂无' }} </el-col>
        <el-col :span="2" class="text-center">
          <p>
            {{ item.goodsRealityAmount }}积分<span v-if="details.cashAmount != 0"
              >+￥{{ details.cashAmount }}</span
            >
          </p>
          <el-tag v-if="details.integralWarning" class="mt-10" type="danger" effect="dark"
            >预警</el-tag
          >
        </el-col>
        <el-col :span="3" class="text-center">
          <span>{{ payType(item.goodsPriceType) }}</span>
        </el-col>
        <!-- <el-col :span="4" class="text-center">
          <span>积分</span>
        </el-col> -->
        <el-col :span="3" class="text-center">
          <OrderStatus :orderItem="details" />
        </el-col>
        <el-col :span="3" class="text-center">
          <div>
            <el-button
              type="text"
              v-if="details.orderStatus === 10"
              style="color: #fc4541"
              @click="shipHandle"
              >立即发货</el-button
            >
          </div>
          <div>
            <el-button type="text" v-if="showShipBtn" style="color: #409eff" @click="viewLogistics"
              >查看物流</el-button
            >
          </div>
          <div>
            <el-button
              type="text"
              class="mt-10"
              v-if="details.mayUpdateAddress && details.orderStatus == 20"
              style="color: #409eff"
              @click="shipHandle('update')"
              >修改物流</el-button
            >
          </div>
        </el-col>
      </el-row>
    </div>

    <OrderShipPopup
      :dialogVisible.sync="dialogVisible"
      :row-data="rowData"
      v-if="dialogVisible"
      @update="update"
    />

    <OrderLogisticsPopup
      :dialogVisible.sync="dialogExpressVisible"
      :expressIdList="details.expressIdList"
      :detailList="details.detailList"
      :orderNo="details.orderNo"
      :expressType="details.expressType"
      v-if="dialogExpressVisible"
      @update="update"
    />
  </div>
</template>

<script>
import OrderStatus from './OrderStatus.vue'
import OrderShipPopup from './OrderShipPopup.vue'
import OrderLogisticsPopup from './OrderLogisticsPopup.vue'
export default {
  name: 'OrderItemPanel',
  components: {
    OrderStatus,
    OrderShipPopup,
    OrderLogisticsPopup
  },
  props: {
    details: {
      type: Object,
      default: () => {
        return {}
      }
    },
    showStoreInfo: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      rowData: [],
      expressIdList: [],
      dialogVisible: false,
      dialogExpressVisible: false
    }
  },
  computed: {
    // 子订单列表
    detailList() {
      return this.details?.detailList
    },
    showShipBtn() {
      // 已发货 待评价 已评价 已完成
      const ids = [20, 30, 31]
      return ids.includes(this.details?.orderStatus)
    },

    // 支付类型
    payType() {
      return function (value) {
        // 1: 积分2: 积分+现金3: 现金
        const obj = {
          1: '积分',
          2: '积分+现金',
          3: '现金'
        }

        return obj[value]
      }
    }
  },
  methods: {
    // 立即发货
    shipHandle(type) {
      this.dialogVisible = true
      this.rowData = {
        type,
        orderNo: this.details.orderNo,
        detailList: this.details?.detailList,
        expressType: this.details.expressType,
        expressIdList: this.details?.expressIdList
      }
    },
    // 查看物流
    viewLogistics(expressIdList) {
      this.expressIdList = expressIdList
      this.dialogExpressVisible = true
    },
    update() {
      this.$emit('update')
    }
  }
}
</script>

<style lang="scss" scoped>
@mixin orderItemPanel() {
  font-size: 14px;
  line-height: 30px;
  padding: 5px 20px;
}
.order-item-panel {
  border: 1px solid #e4e7ed;
  &_top {
    padding: 10px 20px;
    background-color: #e2f1f9;
  }
  &_info {
    @include orderItemPanel();
    background: #e2f1f9;
  }
  &_refund {
    @include orderItemPanel();
    padding: 10px 20px;
    background-color: #e2f1f9;
  }
  &_tabs {
    font-size: 14px;
    line-height: 30px;
    padding: 5px 20px;
    font-weight: bold;
    background: #f7f8fe;
  }
}
.panel-content {
  display: flex;
  align-items: center;
  padding: 15px 0px;
  margin: 0 20px;
  font-size: 12px;
  border-bottom: 1px solid #f2f2f2;
  &:last-child {
    border: none;
  }
  &-img {
    width: 50px;
    height: 50px;
  }
  &-text {
    flex: 1;
    cursor: pointer;
    padding: 2px 0;
  }
  &_title {
    @include ellipsis(2);
    word-break: break-word;
  }
  .price-num-text {
    padding: 10px 0;
  }
  .lease-text {
    padding: 5px 0;
  }
}
</style>
